﻿using System;
using System.Collections;
using System.Web;
using FX.CC.Andon.Business.DataManage;
using FX.CC.Andon.Entity.BasicDataManage;
using FX.CC.Andon.Entity.ReportManage;
using FX.CC.Andon.Utility.Common;
using FX.CC.Andon.Utility.Json;

namespace FX.CC.Andon.WebSite.Service
{
    /// <summary>
    /// DataManageHandler 的摘要说明
    /// </summary>
    public class DataManageHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            try
            {
                var action = DtRequest.GetQueryString("action");
                if (string.IsNullOrEmpty(action)) return;
                var method = this.GetType().GetMethod(action);
                if (method == null) return;
                object[] parameters = { context };
                method.Invoke(this, parameters);
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("ErrorInfo" + ex.Message);
            }
        }

        public void GetUnReliefAbnormalList(HttpContext context)
        {
            var bll = new UnReliefAbnormalBusiness();
            var qcmodel = new AbnormalQcEntity
            {
                BizDateFrom = context.Request["BizDateFrom"],
                BizDateEnd = context.Request["BizDateEnd"],
                LineID = context.Request["LineID"],
                EqCode = context.Request["EqCode"],
                PageIndex = Convert.ToInt32(context.Request["pageIndex"]),
                PageSize = Convert.ToInt32(context.Request["pageSize"]),
                SortField = context.Request["sortField"],
                SortOrder = context.Request["sortOrder"]
            };
            var json = bll.GetUnReliefAbnormalList(qcmodel);
            context.Response.Write(json);
            context.Response.End();
        }

        public void RemoveUnReliefAbnormal(HttpContext context)
        {
            var id = context.Request["EventID"];
            if (String.IsNullOrEmpty(id)) return;
            new UnReliefAbnormalBusiness().RemoveUnReliefAbnormal(id);
        }

        public void ModifyUnreliefAbnormal(HttpContext context)
        {
            var data = context.Request["data"];
            new UnReliefAbnormalBusiness().ModifyUnreliefAbnormal(data);
        }

        public void GetTaskRecMaintainList(HttpContext context)
        {
            var bll = new TaskRecMaintainBusiness();
            var qcmodel = new PrdTaskQcEntity
            {
                BizDateFrom = context.Request["BizDateFrom"],
                BizDateEnd = context.Request["BizDateEnd"],
                ShiftID = context.Request["ShiftID"],
                EqID = context.Request["EqID"],
                PrdCode = context.Request["PrdCode"],
                LineID = context.Request["LineID"],
                PageIndex = Convert.ToInt32(context.Request["pageIndex"]),
                PageSize = Convert.ToInt32(context.Request["pageSize"]),
                SortField = context.Request["sortField"],
                SortOrder = context.Request["sortOrder"]
            };
            var json = bll.GetTaskRecMaintainList(qcmodel);
            context.Response.Write(json);
            context.Response.End();
        }

        public void ModifyTaskRec(HttpContext context)
        {
            var data = context.Request["data"];
            new TaskRecMaintainBusiness().ModifyTaskRec(data);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}